<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\agent\controller;

class AgentLevel extends \app\AgentRest
{
    public function levelList()
    {
        $input = $this->_input;
        $dis[] = ["uniacid", "in", $this->_uniacid_arr];
        $dis[] = ["status", "=", 1];
        $agent_model = new \app\agent\model\AgentLevel();
        $data = $agent_model->levelList($dis, $input["page_count"]);
        return $this->success($data);
    }
    public function agentAdd()
    {
        $input = $this->_input;
        $input["uniacid"] = $this->_uniacid;
        if(!trim($input["title"])) {
            $this->errorMsg("标题不能为空");
        }
        $agent_model = new \app\agent\model\AgentLevel();
        $res = $agent_model->levelAdd($input);
        return $this->success($res);
    }
    public function agentUpdate()
    {
        $input = $this->_input;
        $agent_model = new \app\agent\model\AgentLevel();
        $data = $agent_model->levelUpdate(["id" => $input["id"]], $input);
        return $this->success($data);
    }
    public function agentInfo()
    {
        $input = $this->_input;
        $agent_model = new \app\agent\model\AgentLevel();
        $data = $agent_model->levelInfo(["id" => $input["id"], "status" => 1]);
        return $this->success($data);
    }
    public function levelSelect()
    {
        $dis[] = ["uniacid", "=", $this->_uniacid];
        $dis[] = ["uniacid", "in", $this->_uniacid_arr];
        $agent_model = new \app\agent\model\AgentLevel();
        $data = $agent_model->levelSelect($dis);
        return $this->success($data);
    }
    public function levelDel()
    {
        $input = $this->_input;
        $level_model = new \app\agent\model\AgentLevel();
        $agent_model = new \app\agent\model\AgentList();
        $dis[] = ["level", "=", $input["id"]];
        $dis[] = ["status", ">", -1];
        $info = $agent_model->agentInfo($dis);
        if(!empty($info)) {
            $this->errorMsg("该等级正在被使用,使用代理商：" . $info["user_name"]);
        }
        $data = $level_model->levelUpdate(["id" => $input["id"]], ["status" => -1]);
        return $this->success($data);
    }
}

?>